package com.wsse.common.tool;

/**
 * 控制台输出类
 */
public class Console {
    public static int status = 1;

    /**
     * 控制台打印输出给定对象toString方法
     *
     * @param msg
     */
    public static void log(Object msg) {
        if (msg == null) return;
        if (status == 1) {
            System.out.println(msg.toString() + " [" + Console.class + getCodeInfo() + "]");
        }
    }

    /**
     * 控制台打印输出多个对象toString方法,以空格隔开
     *
     * @param msgs
     */
    public static void log(Object... msgs) {
        if (msgs == null) return;
        StringBuffer sb = new StringBuffer();
        for (Object msg : msgs) {
            if (msg==null)continue;
            sb.append(" ");
            sb.append(msg.toString());
            sb.append(" ");
        }
        System.out.println(sb.toString().trim()+ " [" + Console.class + getCodeInfo() + "]");
    }

    public static String getCodeInfo() {
        StackTraceElement ste = (new Throwable()).getStackTrace()[2];
        return "(" + ste.getFileName() + ":" + ste.getLineNumber() + ")";
    }

}
